package com.garry.common.controller;

import com.garry.common.dto.RegistDto;
import com.garry.user.entity.User;
import com.garry.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by GarryGe on 2016/11/30.
 */
@Controller
public class RegistController {

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/signup")
    public String toregist(){
        return "/common/regist";
    }

    @RequestMapping(value = "/regist",method = RequestMethod.POST)
    public String regist(RegistDto dto){

        User user=new User();
        user.setUsername(dto.getUsername());
        user.setPassword(dto.getPassword());
        try {
            userService.save(user);
        }catch (Exception e){
            e.printStackTrace();
        }
        return "/homepage";
    }
}
